package redisLearning;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.args.ListPosition;

import java.util.List;

public class redisListDemo {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
             test1(jedis);
            // test2(jedis);
        }
    }

    private static void test2(Jedis jedis) {
        jedis.flushAll();
        List<String> res = jedis.blpop(100, "key");
        System.out.println("res[0]: " + res.get(0));
        System.out.println("res[1]: " + res.get(1));
    }

    private static void test1(Jedis jedis) {
        jedis.flushAll();
        jedis.lpush("key", "111", "222", "333");
        List<String> list = jedis.lrange("key", 0, -1);
        System.out.println(list);

        jedis.rpush("key2", "111", "222", "333");
        List<String> list2 = jedis.lrange("key2", 0, -1);
        System.out.println(list2);

        long res = jedis.llen("key");
        System.out.println(res);

        System.out.println(jedis.lindex("key", 1));

        jedis.rpush("key222","a", "b", "c", "d", "e");
        jedis.linsert("key222", ListPosition.BEFORE, "c", "1111");
        System.out.println(jedis.lrange("key222", 0, -1));


    }



}
